#include "widgeteditor.h"
#include "ui_widgeteditor.h"

WidgetEditor::WidgetEditor(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::WidgetEditor)
{
    ui->setupUi(this);
    ui->texture->addItem("(No textures)");
}

WidgetEditor::~WidgetEditor()
{
    delete ui;

}

void WidgetEditor::SetWidget(Data data, Shiny::Widgets::Container* widget)
{
    sf::Vector2f position = widget->GetPosition();
    float        padLeft, padTop, padRight, padBot;
    Shiny::Widgets::AlignType  align;
    Shiny::Widgets::VAlignType valign;

    _currentWidgetData = data;
    widget->GetPadding(padLeft, padTop, padRight, padBot);
    ui->paddingLeft->setValue(padLeft);
    ui->paddingTop->setValue(padTop);
    ui->paddingRight->setValue(padRight);
    ui->paddingBottom->setValue(padBot);
    ui->isVisible->setChecked(widget->IsVisible());
    ui->isMovable->setChecked(widget->IsMovable());
    ui->posY->setValue(position.y);
    ui->posX->setValue(position.x);

    widget->GetAlign(align, valign);
    switch (align)
    {
    case Shiny::Widgets::Left:
	ui->policyPosX->setCurrentIndex(0);
	break ;
    case Shiny::Widgets::Center:
	ui->policyPosX->setCurrentIndex(1);
	break ;
    case Shiny::Widgets::Right:
	ui->policyPosX->setCurrentIndex(2);
	break ;
    case Shiny::Widgets::None:
	ui->policyPosX->setCurrentIndex(3);
	break ;
    }
    switch (valign)
    {
    case Shiny::Widgets::Top:
	ui->policyPosY->setCurrentIndex(0);
	break ;
    case Shiny::Widgets::VCenter:
	ui->policyPosY->setCurrentIndex(1);
	break ;
    case Shiny::Widgets::Bot:
	ui->policyPosY->setCurrentIndex(2);
	break ;
    case Shiny::Widgets::VNone:
	ui->policyPosY->setCurrentIndex(3);
	break ;
    }
}

void WidgetEditor::TextureAdded(QString name)
{
    ui->texture->addItem(name);
}
